package com.yan_jiu_sheng.JavaAdvance.c_multiThread;

/**
 * @author yulongTian
 * @create 2024-05-26 17:16
 */
public class Consumer implements Runnable {
    private BaoZiPu baoZiPu;

    public Consumer(BaoZiPu baoZiPu) {
        this.baoZiPu = baoZiPu;
    }

    @Override
    public void run() {
        while (true) {
            try {
                Thread.sleep(100L);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            synchronized (baoZiPu) {
                if (baoZiPu.isFlag() == false) {
                    try {
                        baoZiPu.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }

                baoZiPu.getCount();

                baoZiPu.setFlag(false);

                baoZiPu.notify();

            }
        }
    }
}
